﻿
#pragma once
#include <iostream>

using namespace std;

class TestCallback {
public:
	int num = 5;
	static int num2;

	typedef void (TestCallback::*CallBack)();
	//CallBack p;
	void call(void* p, CallBack callback);
	//void call(void* p, void (TestCallback::* callback)(void));

	void callBack5();
	void callBack6();
};
int TestCallback::num2 = 6;//静态变量必须初始化


// void TestCallback::call(void* p, void (TestCallback::* callback)(void))
void TestCallback::call(void* p, CallBack callback)
{
	cout << "------调用回调------" << endl;
	TestCallback* temp = (TestCallback*)p;
	// (temp->*callback)();
	(temp->*callback)();
	cout << "------调用结束" << endl;
	cout << endl;
}

void callBack1()
{
	cout << "func1的num = " << endl;
}

void TestCallback::callBack5()
{
	cout << "------start func5------" << endl;
	cout << "func5的num = " << this->num << endl;
	cout << "func5的num2 = " << this->num2 << endl;
	cout << "------end func5------" << endl;
}

void TestCallback::callBack6()
{
	cout << "------start func6------" << endl;
	cout << "func6的num = " << this->num << endl;
	cout << "func6的num2 = " << this->num2 << endl;
	cout << "------end func5------" << endl;
}


int main()
{
	TestCallback t;
	// t.call(&t, &(TestCallback::callBack5));
	// t.call(&t, &TestCallback::callBack6);

	t.call(&t, &(TestCallback::callBack5));

	typedef void (TestCallback::* CallBack)();
	CallBack p=&TestCallback::callBack6;
	t.call(&t, p);

	CallBack q;
	q = &TestCallback::callBack6;
	t.call(&t, q);

	t.call(&t, &TestCallback::callBack6);

	

}

